#!/bin/bash

JSSEED_FILE="dist/js/bluewareui-seed.js"
STYLECSS_FILE="dist/css/style.css"
ZIPFILE_NAME="lastest.zip"
VERSION_FILE="dist/version.txt"


ci_hash=`git rev-parse HEAD`
ci_hash=${ci_hash:0:8}

npm install
if [ $? != 0 ] ; then
  echo "failed at npm install"
  exit 1
fi

# npm test
# if [ $? != 0 ] ; then
#   echo "failed at npm test"
#   exit 1
# fi

./node_modules/.bin/gulp dist
if [ $? != 0 ] ; then
  echo "failed at gulp dist"
  exit 1
fi
echo -n ${ci_hash} > $VERSION_FILE
cp $JSSEED_FILE dist/js/bluewareui-seed-lastest.js
cp $JSSEED_FILE dist/js/bluewareui-seed-${ci_hash}.js
cp $STYLECSS_FILE dist/css/style-lastest.css
cp $STYLECSS_FILE dist/css/style-${ci_hash}.css
cd dist/
zip -rq $ZIPFILE_NAME ./*

if [ $? != 0 ] ; then
  echo "failed at zip dist"
  exit 1
fi
